#页面基类：
#放一些通用的页面操作、通用的属性：driver、base_url
import time

class PageBase(object):
    def __init__(self,driver,base_url):
        self.driver=driver
        self.base_url=base_url


    #通用操作：打开某网址
    def open(self,path_url):#/site/products/id/17
        self.driver.get(f"{self.base_url}{path_url}")

    #通用操作：点击某元素
    def click(self,loc):
        by=loc[0]
        value=loc[1]
        ele=self.driver.find_element(by,value)
        ele.click()

    #通用操作：对某元素进行文本输入
    def input(self,loc,data):
        by = loc[0]
        value = loc[1]
        ele = self.driver.find_element(by, value)
        ele.send_keys(data)

    #通用操作：获取某元素的文本内容
    def getEleText(self,loc):
        by = loc[0]
        value = loc[1]
        ele = self.driver.find_element(by, value)
        return ele.text.strip()

    #通用操作：获取某元素的某属性的值
    def getEleAttr(self,loc,attrName):
        by = loc[0]
        value = loc[1]
        ele = self.driver.find_element(by, value)
        return ele.get_attribute(attrName)

    #截图,并返回图片名称
    def savePng(self,serviceName,key):
        currentTimeStr=time.strftime("%Y%m%d%H%M%S")
        imgName=f"{serviceName}_{key}_20240709095401.png"
        self.driver.get_screenshot_as_file(f"./screen/{imgName}")
        return imgName